#include "PestaniaProperties.h"
PestaniaProperties::PestaniaProperties(const std::string& rute):abmPro(rute),VistaPro(abmPro),Boton1("Escribir"),Boton2("Eliminar"){
    this->abmPro.LevantarFile();
    //***********************************************
    this->Label_Value.set_text("Valor");
    this->vbox_CajaValue.add( this->Label_Value );
    this->vbox_CajaValue.add( this->Entry_Value );
    //***********************************************
    this->Label_Key.set_text("Key");
    this->vbox_CajaKey.add( this->Label_Key );
    this->vbox_CajaKey.add( this->Entry_Key );
    //***********************************************
    this->hbox_BoxKV.add(this->vbox_CajaKey);
    this->hbox_BoxKV.add(this->vbox_CajaValue);
    //***********************************************
    this->hbbox_Botonera.add(this->Boton1);
    this->hbbox_Botonera.add(this->Boton2);
    this->hbbox_Botonera.set_layout(Gtk::BUTTONBOX_SPREAD);
    this->Boton1.signal_clicked().connect(sigc::mem_fun(*this,&PestaniaProperties::on_boton1_clickeado));
    this->Boton2.signal_clicked().connect(sigc::mem_fun(*this,&PestaniaProperties::on_boton2_clickeado));
    //***********************************************
    this->vbox_PantallaKeyValue.add(this->hbox_BoxKV);
    this->vbox_PantallaKeyValue.add(this->hbbox_Botonera);
    this->frame_KV.set_label("Modificar Archivo de Configuración");
    this->frame_KV.set_shadow_type(Gtk::SHADOW_OUT);
    this->frame_KV.add( this->vbox_PantallaKeyValue );
    this->frame_KV.set_border_width(20);
    //***********************************************
    this->add(this->frame_KV);

    this->frame_ArchProperties.set_label("Información de Archivo de Configuración");
    this->frame_ArchProperties.add(this->VistaPro);
    this->VistaPro.ActualizarVista();
    this->frame_ArchProperties.set_border_width(20);
    this->add( this->frame_ArchProperties );
}

void PestaniaProperties::on_boton1_clickeado()
{
    std::string Key = this->Entry_Key.get_text();
    std::string Value = this->Entry_Value.get_text();
    this->Entry_Key.delete_text(0,this->Entry_Key.get_text_length());
    this->Entry_Value.delete_text(0,this->Entry_Value.get_text_length());
    this->abmPro.Escribir(Key,Value);
    this->VistaPro.ActualizarVista();
}

void PestaniaProperties::on_boton2_clickeado()
{
    std::string Key = this->Entry_Key.get_text();
    this->Entry_Key.delete_text(0,this->Entry_Key.get_text_length());
    this->abmPro.Eliminar(Key);
    this->VistaPro.ActualizarVista();
}
